﻿using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System;

namespace launcher.Common
{
    internal static class Conversion
    {
        public static bool Not(bool value)
        {
            return !value;
        }

        public static Symbol PausedToSymbol(bool paused)
        {
            return paused ? Symbol.Play : Symbol.Pause;
        }

        public static string KeyboardAcceleratorToText(KeyboardAccelerator accel)
        {
            if (accel == null) { return null; }
            
            StringBuilder builder = new();
            if (accel.Modifiers.HasFlag(VirtualKeyModifiers.Control))
            {
                builder.Append("Ctrl");
            }
            if (accel.Modifiers.HasFlag(VirtualKeyModifiers.Menu))
            {
                if (builder.Length > 0)
                {
                    builder.Append("+");
                }
                builder.Append("Alt");
            }
            if (accel.Modifiers.HasFlag(VirtualKeyModifiers.Shift))
            {
                if (builder.Length > 0)
                {
                    builder.Append("+");
                }
                builder.Append("Shift");
            }
            if (accel.Modifiers.HasFlag(VirtualKeyModifiers.Windows))
            {
                if (builder.Length > 0)
                {
                    builder.Append("+");
                }
                builder.Append("Win");
            }
            if (builder.Length > 0)
            {
                builder.Append("+");
            }

            return builder.Append(accel.Key.ToString()).ToString();
        }
    }
}
